import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mtf/app/modules/change_psw_module/change_psw_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';
import 'package:mtf/app/widget/HcIconText.dart';
import 'package:mtf/app/widget/SettingBar.dart';
import 'package:mtf/app/widget/VercodeTimerWidget.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class changePswPage extends GetView<changePswController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarLeftTitle(title: "修改登录密码"),
      body: Container(
        width: double.infinity,
        child: ListView.builder(
          itemBuilder: (context, index) {
            if (index == 0) {
              return Container(
                margin: EdgeInsets.all(10),
                padding: EdgeInsets.symmetric(horizontal: 10),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10)),
                child: Column(
                  children: [
                    Obx(() {
                      return SettingBar(
                        paddingHorizontal: 0,
                        leftIconSpace: 0,
                        leftText: "手机号",
                        rightText: "${controller.user.value.phone}",
                        showDivider: true,
                      );
                    }),
                    Container(
                      width: double.infinity,
                      child: Flex(
                        direction: Axis.horizontal,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("验证码"),
                          Row(
                            children: [
                              Container(
                                padding: EdgeInsets.symmetric(horizontal: 10),
                                width: 150,
                                child: TextField(
                                  textAlign: TextAlign.right,
                                  decoration: InputDecoration(
                                    hintText: "请输入验证码",
                                    hintStyle: TextStyle(
                                        fontSize: 14, color: c_999999),
                                    border: InputBorder.none,
                                  ),
                                  style:
                                  TextStyle(color: c_333333, fontSize: 14),
                                  controller: controller.yzmController,
                                ),
                              ),
                              Container(
                                  height: 35,
                                  decoration: BoxDecoration(
                                    border: Border.all(
                                        color: c_f12f38, width: 1),
                                    borderRadius: BorderRadius.circular(16),
                                  ),
                                  child: VercodeTimerWidget(
                                    controller.verController,
                                    onPressed: () {
                                      controller.reqYzm();
                                    },
                                    textColor: c_f12f38,
                                  ))
                            ],
                          )
                        ],
                      ),
                    ),
                    Divider(
                      height: 1,
                    ),
                    Flex(
                      direction: Axis.horizontal,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("登录密码"),
                        Obx(() {
                          return Expanded(
                            flex: 1,
                            child: HcIconText(
                              label: TextField(
                                textAlign: TextAlign.right,
                                obscureText: controller.Obscure,
                                decoration: InputDecoration(
                                    hintText: "请输入登录密码",
                                    hintStyle:
                                    TextStyle(fontSize: 14, color: c_999999),
                                    border: InputBorder.none,
                                    suffixIcon: IconButton(
                                      splashColor: Colors.transparent,
                                      iconSize: 18,
                                      icon: Icon(controller.Obscure
                                          ? Icons.visibility
                                          : Icons.visibility_off),
                                      onPressed: () {
                                        controller.Obscure =
                                        !controller.Obscure;
                                      },
                                    )),
                                style: TextStyle(color: c_333333, fontSize: 14),
                                controller: controller.psw1Controller,
                              ),
                            ),
                          );
                        })
                      ],
                    ),
                    Divider(height: 1,),
                    Flex(
                      direction: Axis.horizontal,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("确认密码"),
                        Obx(() {
                          return Expanded(
                            flex: 1,
                            child: HcIconText(
                              label: TextField(
                                textAlign: TextAlign.right,
                                obscureText: controller.TwoObscure,
                                decoration: InputDecoration(
                                    hintText: "请再次输入登录密码",
                                    hintStyle:
                                    TextStyle(fontSize: 14, color: c_999999),
                                    border: InputBorder.none,
                                    suffixIcon: IconButton(
                                      splashColor: Colors.transparent,
                                      iconSize: 18,
                                      icon: Icon(controller.TwoObscure
                                          ? Icons.visibility
                                          : Icons.visibility_off),
                                      onPressed: () {
                                        controller.TwoObscure =
                                        !controller.TwoObscure;
                                      },
                                    )),
                                style: TextStyle(color: c_333333, fontSize: 14),
                                controller: controller.psw2Controller,
                              ),
                            ),
                          );
                        })
                      ],
                    ),
                  ],
                ),
              );
            } else {
              return Container(
                margin: const EdgeInsets.only(top: 30, left: 10, right: 10),
                width: double.maxFinite,
                height: 48,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(24),
                  color: c_f12f38,
                ),
                child: TextButton(
                    child: Text("提交",
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.bold)),
                    onPressed: () {
                      controller.reqChangePsw();
                    }),
              );
            }
          },
          itemCount: 2,
        ),
      ),
    );
  }
}
